#include "vlerasercontextwidget.h"
#include "erasertool.h"

VLEraserContextWidget::VLEraserContextWidget(QWidget *parent) :
    VLContextWidget(parent)
{
    layout = setupLayout();

    nameLabel = createAndAddLabel(layout, tr("ERASER"));

    shapeLabel = createAndAddLabel(layout, tr("Shape"));
    shapesList = new QStringList();
    *shapesList << "Cube" << "Cuboid" << "Sphere" << "Pyramid";
    shapeBox = createAndAddComboBox(layout, shapesList);
    connect(shapeBox, SIGNAL(activated(int)), this, SLOT(setShape(int)));

    sizeLabel = createAndAddLabel(layout, tr("Size"));
    sizeBox = createAndAddSpinBox(layout, 1, 100);
    connect(sizeBox, SIGNAL(valueChanged(int)), this, SLOT(setSize(int)));

    breadthLabel = createAndAddLabel(layout, tr("Breadth"));
    breadthBox = createAndAddSpinBox(layout, 1, 100);
    connect(breadthBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));

    heightLabel = createAndAddLabel(layout, tr("Height"));
    heightBox = createAndAddSpinBox(layout, 1, 100);
    connect(heightBox, SIGNAL(valueChanged(int)), this, SLOT(setBreadth(int)));

    setDefaults();
}

void VLEraserContextWidget::setShape(int shape) {
    switch (shape + 1) {
        case CUBE:
            breadthBox->setDisabled(true);
            heightBox->setDisabled(true);
            break;
        case CUBOID:
            breadthBox->setDisabled(false);
            heightBox->setDisabled(false);
            break;
        case SPHERE:
            breadthBox->setDisabled(true);
            heightBox->setDisabled(true);
            break;
        case PYRAMID:
            breadthBox->setDisabled(true);
            heightBox->setDisabled(false);
            break;
        default:
            break;
    }

    emit shapeChanged(shape);
}

void VLEraserContextWidget::setSize(int size) {
    emit sizeChanged(size);
}

void VLEraserContextWidget::setHeight(int height) {
    emit heightChanged(height);
}

void VLEraserContextWidget::setBreadth(int breadth) {
    emit breadthChanged(breadth);
}

void VLEraserContextWidget::setDefaults() {
    int shape = TOOL_ERASER->getShape() - 1;
    int size = TOOL_ERASER->getSize();
    int height = TOOL_ERASER->getHeight();
    int breadth = TOOL_ERASER->getBreadth();

    // ISSUE: hard-coded. need to find a way to access.
//    int shape = 1;
//    int size = 1;
//    int height = 1;
//    int breadth = 1;

    sizeBox->setValue(size);
    heightBox->setValue(height);
    breadthBox->setValue(breadth);
    shapeBox->setCurrentIndex(shape);
    setShape(shape);
}
